package com.greenant.store.activity;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.avos.avoscloud.AVUser;
import com.greenant.store.R;
import com.greenant.store.utils.NotificationUtil;
import com.greenant.store.utils.UtilTools;
import com.greenant.store.version.DownloadManager;
import com.lsarah.utils.SystemBarTintManager;

public class SettingsActivity extends BaseActivity {
	private Button btn_login;
	private Handler mHandler = new Handler(Looper.getMainLooper());
	private Context context;
	private String teleP = "";
	private TextView versionName;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		SystemBarTintManager.setContentView(this, R.layout.activity_settings,
				getResources().getColor(R.color.firebrick));
		context = this;
		btn_login = (Button) findViewById(R.id.btn_login);
		versionName=(TextView)findViewById(R.id.versionName);
		try {
			versionName.setText(this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName);
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}

	}

	public void goBack(View view) {
		finish();
	}

	public void manageMyInfo(View view) {
		if (UtilTools.isUserLogined(this)) {
			Intent intent = new Intent(this, MyInfoActivity.class);
			startActivity(intent);
		}
	}
	
	public void manageEmrecv(View view) {
		if (UtilTools.isUserLogined(this)) {
			Intent intent = new Intent(this, ExpressManageActivity.class);
			startActivity(intent);
		}
	}

	public void promiseService(View view) {

		 Intent intent = new Intent(this, DescFuncActivity.class);
		 startActivity(intent);

	}

	public void cleanAllCache(View view) {
	}

	public void logout(View view) {
		if (UtilTools.isUserLogined(this)) {
			NotificationUtil.unRegisterNotificationWhenUserChange(this);
			AVUser.logOut();
			UtilTools.showMyToast(this, this.getString(R.string.success));
			btn_login.setText(R.string.activity_login_login);
		}
		
		Intent intent = new Intent(this, LoginActivity.class);
		startActivity(intent);
		this.finish();
	}

	@Override
	protected void onResume() {
		super.onResume();

		AVUser currentUser = AVUser.getCurrentUser();
		if (currentUser != null) {
			btn_login.setText(R.string.settings_logout);
		} else {
			btn_login.setText(R.string.activity_login_login);
		}
	}

	public void showAbout(View view) {
		 Intent intent = new Intent(this, AboutAppActivity.class);
		 startActivity(intent);
	}

	public void checkUpdate(View view) {
		//检查更新
        DownloadManager downloadManager=new DownloadManager(this,true,true);
        downloadManager.checkDownload();
	}

}
